﻿// ===============================================================================
// XCI.NET 西安交通信息WinForm开发框架 2018 版权所有
// ===============================================================================
using System;

namespace XCI.Config
{
    /// <summary>
    /// 系统配置接口
    /// </summary>
    public interface IConfigProvider
    {
        /// <summary>
        /// 加载配置
        /// </summary>
        void Load();

        /// <summary>
        /// 保存配置
        /// </summary>
        void Save();

        /// <summary>
        /// 获取指定名称的配置对象
        /// </summary>
        /// <typeparam name="T">配置类型</typeparam>
        /// <param name="key">配置名称</param>
        /// <param name="defaultValue">如果未找到指定名称的配置对象时,返回此默认值</param>
        /// <returns>返回指定名称的配置对象</returns>
        T Get<T>(string key, Func<T> defaultValue = null) where T : class;

        /// <summary>
        /// 设置指定名称的配置对象
        /// </summary>
        /// <typeparam name="T">配置类型</typeparam>
        /// <param name="key">配置名称</param>
        /// <param name="value">配置对象</param>
        void Set<T>(string key, T value) where T : class;

        /// <summary>
        /// 读取应用程序配置
        /// </summary>
        /// <param name="key">键名</param>
        /// <param name="defaultValue">如果找不到,返回的默认值</param>
        /// <returns>返回key对应的值,如果找不到key则返回指定的默认值</returns>
        string GetAppSettings(string key, string defaultValue = "");

        /// <summary>
        /// 设置应用程序配置
        /// </summary>
        /// <param name="key">键名</param>
        /// <param name="value">键值</param>
        void SetAppSettings(string key, string value);
    }
}